<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<div>
	&nbsp;&nbsp;&nbsp; 说明：请在下面内容进行修改，带<span style="color: red">*</span>为必填内容
</div>

<form action="../writeModifyDonate" method="post" name="modifyDonateForm">
	<table cellpadding="4" cellspacing="0" width="600" align="center">
		<tr>
			<td>
				<table width="100">
					<tr>
						<td>
							&nbsp;
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				ID编号：
			</td>
			<td>
				<input type="text" name="modifyDonateId" id="modifyDonateId"
					readonly="readonly" value="${modifyDonate.id}" size="35" />
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠名称：
			</td>
			<td>
				<input type="text" name="modifyDonateName" id="modifyDonateName"
					value="${modifyDonate.donate_name }" size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠金额：
			</td>
			<td>
				<input type="text" name="modifyDonatePrice" id="modifyDonatePrice"
					value="${modifyDonate.donate_price }" size="35" />元
				<span style="color: red">*</span>最低1元,最多精确到分
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠项目或用途：
			</td>
			<td>
<!--				<input type="text" name="modifyDonateNeed" id="modifyDonateNeed"-->
<!--					value="${modifyDonate.donate_need }" size="35" />-->
					<select name="choice_project_title">
						<option value="无指定用途">无指定用途</option>
						<c:forEach items="${project_title_list}" var="project_title">
							<option value="${project_title}">${project_title}</option>
						</c:forEach>
					</select>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者邮箱：
			</td>
			<td>
				<input type="text" name="modifyDonateEmail" id="modifyDonateEmail"
					value="${modifyDonate.donate_email}" size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者电话号码：
			</td>
			<td>
				<input type="text" name="modifyDonateTelephone"
					id="modifyDonateTelephone" value="${modifyDonate.donate_telephone}"
					size="35" />
				&nbsp;&nbsp;11位手机号码
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者地址：
			</td>
			<td>
				<input type="text" name="modifyDonateAddress"
					id="modifyDonateAddress" value="${modifyDonate.donate_address}"
					size="35" />
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者邮政编码：
			</td>
			<td>
				<input type="text" name="modifyDonatePostalcode"
					id="modifyDonatePostalcode"
					value="${modifyDonate.donate_postalcode}" size="35" />
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				是否校友：
			</td>
			<td>
				<input type="radio" name="modifyDonateAlumni"
					id="modifyDonateAlumniYes" value="yes" checked onclick="moodifyHideYes()"/>
				校友
				<input type="radio" name="modifyDonateAlumni"
					id="modifyDonateAlumniNo" value="no" onclick="moodifyHideNo()"/>
				非校友
			</td>
		</tr>
		<tr id="modifyTr">
			<td align="left" width="130">
				<div id="">入校时间及院部：</div>
			</td>
			<td>
				<input type="text" name="modifyDonateClassInformation"
					id="modifyDonateClassInformation"
					value="${modifyDonate.donate_classInformation}" size="35" />
				<span style="color: red">*</span>
			</td>
		</tr>
		<tr>
			<td align="left" width="130">
				捐赠者留言：
			</td>
			<td>
				<textarea rows="10" cols="50" name="modifyDonateRemark" >${modifyDonate.remark}</textarea>
			</td>
		</tr>
		<tr>
			<td style="padding-left: 200" colspan="2">
				<input type="button" value="修改" onclick="submitcheck()" name="modifyDonateButton" id="modifyDonateButton"/>
			</td>
		</tr>
	</table>
</form>

<script type="text/javascript">
	
	//默认设置是否是校友
	if("${modifyDonate.donate_alumni}" == "yes") {
		moodifyHideYes();
		for(var i=0;i<document.modifyDonateForm.modifyDonateAlumni.length;i++) {
			if("${modifyDonate.donate_alumni}" == document.modifyDonateForm.modifyDonateAlumni[i].value) {
				document.modifyDonateForm.modifyDonateAlumni[i].checked = true;
				break;
			}
			document.modifyDonateForm.modifyDonateAlumni[i].checked = false;
		}
	}else {
		moodifyHideNo();
		for(var i=0;i<document.modifyDonateForm.modifyDonateAlumni.length;i++) {
			if("${modifyDonate.donate_alumni}" == document.modifyDonateForm.modifyDonateAlumni[i].value) {
				document.modifyDonateForm.modifyDonateAlumni[i].checked = true;
				break;
			}
			document.modifyDonateForm.modifyDonateAlumni[i].checked = false;
		}
	}
	
	//设置属于哪个基金会项目
	for(var i=0;i<document.modifyDonateForm.choice_project_title.length;i++) {
		if(document.modifyDonateForm.choice_project_title[i].value == "${modifyDonate.donate_need}") {
			document.modifyDonateForm.choice_project_title[i].selected = true;
		}
	}
	

	function moodifyHideYes() {
		document.getElementById("modifyTr").style.display="none";
		document.getElementById("modifyTr").style.display="";
	}
	function moodifyHideNo() {
		document.getElementById("modifyTr").style.display="";
		document.getElementById("modifyTr").style.display="none";
	}
	//function get(){
	//	for(var i=0;i<document.f.define.length;i++)
	//		if(document.f.define[i].checked) alert(document.f.define[i].value)
	//}
	
	function submitcheck() {
		var name = document.modifyDonateForm.modifyDonateName.value;
		var price = document.modifyDonateForm.modifyDonatePrice.value;
		var email = document.modifyDonateForm.modifyDonateEmail.value;
		var telephone = document.modifyDonateForm.modifyDonateTelephone.value;
		var postalcode = document.modifyDonateForm.modifyDonatePostalcode.value;
		var alumni = "";
		
		for(var i=0;i<document.modifyDonateForm.modifyDonateAlumni.length;i++) {
			if(document.modifyDonateForm.modifyDonateAlumni[i].checked) {
				alumni = document.modifyDonateForm.modifyDonateAlumni[i].value;
			}
		}

		//var regexPrice = /^([1-9][0-9])|([1-9][0-9]*\.[0-9]*)$/;
		var regexPrice1 = /^[1-9][0-9]*$/;
		var regexPrice2 = /^[1-9][0-9]*\.[0-9]{2}$/;
		var regexEmail = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
		var regexTelePhone = /^[1][3-8][0-9]{9}$/;
		var regexPostcode = /^[1-9][0-9]{5}$/;

		if(name == "") {
			alert("输入的捐赠名称不能为空!");
		} else if(price == "") {
			alert("输入的捐赠金额不能为空!");
		} else if(!regexPrice1.test(price) && !regexPrice2.test(price)) {
			alert("输入的捐赠金额格式不正确!")
		} else if(email == "") {
			alert("输入的邮箱不能为空!")
		} else if(!regexEmail.test(email)) {
			alert("输入的邮箱格式不正确!")
		} else if(telephone != "" && !regexTelePhone.test(telephone)) {
			alert("输入的电话号码格式不正确!")
		} else if(postalcode != "" && !regexPostcode.test(postalcode)) {
			alert("输入的邮政编码格式不正确!");
		} else if(alumni == "yes") {
			var classInformation = document.modifyDonateForm.modifyDonateClassInformation.value;
			if(classInformation == "") {
				alert("输入的入校时间及院部不能为空!")
			} else {
				document.modifyDonateForm.submit();
			}
		} else {
				document.modifyDonateForm.submit();
		}
	}
	
	
	
</script>